package com.aneliya.command.loginDialog;

import javax.swing.JOptionPane;

import com.aneliya.framework.mvc.Facade;
import com.aneliya.framework.mvc.controller.ICommand;
import com.aneliya.framework.mvc.controller.MVCEvent;
import com.aneliya.mediator.LoginDialogMediator;
import com.aneliya.proxy.UserProxy;

public class RegistrationFailedCommand implements ICommand {

	private static final String ERROR_POPUP_TITLE = "Registration Failed";
	private static final String ERROR_POPUP_MESSAGE = "Registration unsuccessful! Please, try again!";
	
	public void execute(MVCEvent event) {		
		try {
			UserProxy userProxy = 
				(UserProxy) Facade.getInstance().retrieveProxy("UserProxy");
			userProxy.setAuthenticatedUser(null);
			
			LoginDialogMediator loginDialogMediator = 
				(LoginDialogMediator)Facade.getInstance().retrieveMediator("LoginDialogMediator");
			JOptionPane.showMessageDialog(loginDialogMediator.getLoginDialog(), 
					ERROR_POPUP_MESSAGE, ERROR_POPUP_TITLE, JOptionPane.ERROR_MESSAGE);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
